import javax.swing.*;
import java.io.*;
import java.text.DecimalFormat;

public class InventoryWindow extends JTextArea implements Serializable {

	private DecimalFormat df = new DecimalFormat("#.#");
	
	public void Refresh(Player a) {
		setText("");
		append("Inventory:\n\n");
		append("Gold: " + a.getGold() + "\n\n");
		try {
			if (a.get_Main_Hand().getName().equalsIgnoreCase("Fists")) {
				append("Main Hand: Unarmed\n");
			} else {
				append("Main Hand: " + a.get_Main_Hand().getName().substring(0, 1).toUpperCase() + a.get_Main_Hand().getName().substring(1) + "\n");
			}
		} catch (NullPointerException e) {
			append("Main Hand: Unarmed\n");
		}
		
		append("Off-Hand: None\n\n");
		
		try {
		append("Head: " + a.getHead().getName().substring(0, 1).toUpperCase() + a.getHead().getName().substring(1) + "\n");
		} catch (NullPointerException e) {
			append("Head: None\n");
		}
		
		try {
			append("Shoulders: " + a.getShoulders().getName().substring(0, 1).toUpperCase() + a.getShoulders().getName().substring(1) + "\n");
			} catch (NullPointerException e) {
				append("Shoulders: None\n");
			}
			
		try {
			append("Chest: " + a.getChest().getName().substring(0, 1).toUpperCase() + a.getChest().getName().substring(1) + "\n");
			} catch (NullPointerException e) {
				append("Chest: None\n");
			}
			
		try {
			append("Hands: " + a.getHands().getName().substring(0, 1).toUpperCase() + a.getHands().getName().substring(1) + "\n");
			} catch (NullPointerException e) {
				append("Hands: None\n");
			}

		try {
			append("Legs: " + a.getLegs().getName().substring(0, 1).toUpperCase() + a.getLegs().getName().substring(1) + "\n");
			} catch (NullPointerException e) {
				append("Legs: None\n");
			}

		try {
			append("Feet: " + a.getFeet().getName().substring(0, 1).toUpperCase() + a.getFeet().getName().substring(1) + "\n\n");
			} catch (NullPointerException e) {
				append("Feet: None\n\n");
			}
			
		append("Items in backpack:\n\n");
		
		for (Entity b : a.getInventory()) {
			if(b.isVisible() == true) {
			append(b.getName().substring(0, 1).toUpperCase() + b.getName().substring(1) + "\n");
			}
		}
		append("\nCarried Weight: " + df.format(a.carriedWeight()));
		append("\nMax Weight: " + a.maxWeight());
	}
	
}
